<?php
session_start();
include "../../config/koneksi.php";
include "../../config/library.php";
include "../../config/fungsi_thumb.php";
include "../../config/fungsi_seo.php";

$module=$_GET[module];
$act=$_GET[act];

// Hapus member
if ($module=='member' AND $act=='hapus'){
  mysql_query("DELETE FROM member WHERE id_member='$_GET[id]'");
  header('location:../../media.php?module='.$module);
}

// Input member
elseif ($module=='member' AND $act=='input'){
  $lokasi_file = $_FILES['fupload']['tmp_name'];
  $nama_file   = $_FILES['fupload']['name'];

  //$namalengkap_seo      = seo_title($_POST['namalengkap']);

  // Apabila ada gambar yang diupload
  if (!empty($lokasi_file)){
    UploadMember($nama_file);
	$pass=md5($_POST[password]);
    mysql_query("INSERT INTO member(id_member, password, namalengkap, 
                                    tgl_lahir, jenis_kelamin, status, alamat, gol_darah, 
                                    gambar, username) 
                            VALUES('$_POST[id_member]', '$pass', '$_POST[namalengkap]', 
								   '$_POST[tgl_lahir]', '$_POST[jenis_kelamin]', '$_POST[status]', '$_POST[alamat]', 
                                   '$_POST[gol_darah]', '$nama_file', '$_SESSION[namauser]')");
  }
  else{
	$pass=md5($_POST[password]);
    mysql_query("INSERT INTO member(id_member, password, namalengkap, 
                                    tgl_lahir, jenis_kelamin, status, alamat, gol_darah, username) 
                            VALUES('$_POST[id_member]', '$pass', '$_POST[namalengkap]', 
								   '$_POST[tgl_lahir]', '$_POST[jenis_kelamin]', '$_POST[status]', '$_POST[alamat]', 
                                   '$_POST[gol_darah]', '$_SESSION[namauser]')");
  }
  header('location:../../media.php?module='.$module);
}

// Update member
elseif ($module=='member' AND $act=='update'){
  $lokasi_file = $_FILES['fupload']['tmp_name'];
  $nama_file   = $_FILES['fupload']['name'];
  
  //$nama_wisata_seo      = seo_title($_POST['nama_wisata']);

  // Apabila gambar tidak diganti
  if (empty($lokasi_file)){
    mysql_query("UPDATE member SET 
							 namalengkap = '$_POST[namalengkap]', 
							 tgl_lahir = '$_POST[tgl_lahir]', 
							 jenis_kelamin = '$_POST[jenis_kelamin]', 
							 status = '$_POST[status]',
							 alamat = '$_POST[alamat]',
							 gol_darah = '$_POST[gol_darah]'
                             WHERE id_member = '$_POST[id]'");
  }
  else{
    UploadMember($nama_file);
    mysql_query("UPDATE member SET
							 namalengkap = '$_POST[namalengkap]', 
							 tgl_lahir = '$_POST[tgl_lahir]', 
							 jenis_kelamin = '$_POST[jenis_kelamin]', 
							 status = '$_POST[status]',
							 alamat = '$_POST[alamat]',
							 gol_darah = '$_POST[gol_darah]',
                                   gambar    = '$nama_file'   
                             WHERE id_member= '$_POST[id]'");
  }
  header('location:../../media.php?module='.$module);
}
?>
